package com.example.system.controller.sysuser;

import com.example.common.core.constants.HttpConstants;
import com.example.common.core.controller.BaseController;
import com.example.common.core.domain.R;
import com.example.system.domain.sysuser.dto.SysUserDTO;
import com.example.system.domain.sysuser.dto.LoginDTO;
import com.example.system.domain.sysuser.vo.LoginUserVO;
import com.example.system.service.sysuser.ISysUserService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sysuser")
@Tag(name = "管理员用户API")
public class SysUserController extends BaseController {
    @Autowired
    private ISysUserService sysUserService;

    @PostMapping ("/login")
    public R<String> login(@RequestBody @Validated LoginDTO loginDTO) {
        R<String> result = sysUserService.login(loginDTO.getUserAccount(), loginDTO.getUserPassword());
        return result;
    }

    @PostMapping ("/add")
    public R<Void> add(@RequestBody @Validated SysUserDTO sysUserDTO) {
        return toR(sysUserService.add(sysUserDTO));
    }

    @GetMapping ("/info")
    public R<LoginUserVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return sysUserService.info(token);
    }

    @DeleteMapping ("/exitlogin")
    public R<Void> exitLogin(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return toR(sysUserService.exitLogin(token));
    }

}
